package com.kakarote.oa.constart;

import cn.hutool.core.date.DateUtil;
import lombok.Getter;

import java.util.Date;

@Getter
public enum SubmitType {

    NONE(0, "不限制"),
    DAY(1, "每天"),
    WEEK(2, "每周"),
    MONTH(3, "每月");

    private Integer type;
    private String remark;


    SubmitType(Integer type, String remark) {
        this.type = type;
        this.remark = remark;
    }

    public String getStartTime(Date date) {
        switch (getType()) {
            case 1:
                return DateUtil.beginOfDay(date).toMsStr();
            case 2:
                return DateUtil.beginOfWeek(date).toMsStr();
            case 3:
                return DateUtil.beginOfMonth(date).toMsStr();
        }
        return null;
    }

    public String getEndTime(Date date) {
        switch (getType()) {
            case 1:
                return DateUtil.endOfDay(date).toMsStr();
            case 2:
                return DateUtil.endOfWeek(date).toMsStr();
            case 3:
                return DateUtil.endOfMonth(date).toMsStr();
        }
        return null;
    }


    public static SubmitType valueOf(Integer type) {
        for (SubmitType c : SubmitType.values()) {
            if (c.getType().equals(type)) {
                return c;
            }
        }
        return SubmitType.NONE;
    }

}
